package com.boyi.shared.common;

import java.io.Serializable;

import com.boyi.shared.http.base.ObjectResp;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import org.springframework.stereotype.Component;

/**
 * 调用外部服务返回的通用数据对象，包装了服务端调用的返回数据，
 * 通过success字段标识调用是否成功，通过msg/data标识调用失
 * 败时的提示信息
 *
 * @param <T>
 */
@JsonInclude(Include.NON_NULL)
public class Result<T> implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1905775611728626568L;

    /**
     * 返回的对象
     */
    protected T data;
    /**
     * 错误码
     * 错误码规则：应用名_错误信息的英文描述
     * 如WASS_USER_NOT_FOUND
     */
    protected int code = 200;

    /**
     * 错误信息
     * 错误信息的业务描述
     */
    protected String msg = "success";


    public Result(T data) {
        this.data = data;
    }

    public Result(int msgCode, String msgInfo) {
        this.code = msgCode;
        this.msg = msgInfo;
    }

    public Result(int msgCode, String msgInfo, T data) {
        this.code = msgCode;
        this.msg = msgInfo;
        this.data = data;
    }

    public Result() {

    }

    /**
     * @return the data
     */
    public T getData() {
        return data;
    }

    /**
     * @param data the data to set
     */
    public void setData(T data) {
        this.data = data;
    }

    /**
     * @return the code
     */
    public int getCode() {
        return code;
    }

    /**
     * @param code the code to set
     */
    public void setCode(int code) {
        this.code = code;
    }

    /**
     * @return the msg
     */
    public String getMsg() {
        return msg;
    }

    /**
     * @param msg the msg to set
     */
    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setMessage(Message msg) {
        this.code = msg.code;
        this.msg = msg.msg;
    }

}
